package com.mk.api.sys;

import com.mk.base.model.response.Rsp;
import com.mk.model.request.RoleResourceRequest;
import com.mk.service.IRoleResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: yq
 * @Description:
 * @Date: Created in 3:43 PM 3/14/18
 */
@RestController
@RequestMapping("/role/resource")
public class RoleResourceApi {

    @Autowired
    private IRoleResourceService roleResourceService;

    @RequestMapping(value = "/modify",method = RequestMethod.POST)
    public Rsp modifyRoleResource(@RequestBody RoleResourceRequest request){
        try{
            if(roleResourceService.changeRolePermissions(request.getRoleId(),request.getResourceIds()))
                return Rsp.SUCCESS("修改角色拥有的资源成功");
            else
                return Rsp.ERROR("修改角色拥有的资源失败");
        }catch (Exception e){
            return Rsp.ERROR(e.getMessage());
        }
    }
}
